# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=mold
pkgver=2.4.0
pkgrel=0
pkgdesc="fast modern linker"
url="https://github.com/rui314/mold"
arch="all"
license="MIT"
_llvmver=17
makedepends="
	clang$_llvmver
	cmake
	linux-headers
	llvm$_llvmver-dev
	mimalloc2-dev
	onetbb-dev
	openssl-dev
	samurai
	xxhash-dev
	zlib-dev
	zstd-dev
	"
checkdepends="
	bash
	dwarf-tools
	grep
	perl
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/rui314/mold/archive/refs/tags/v$pkgver.tar.gz
	xxhash.patch
	"

case "$CARCH" in
s390x)
	# copyrel, shared-abs-sym, tls-large-alignment, tls-small-alignment
	options="!check"
	;;
esac
case "$CARCH" in
s390x|riscv64)
	;;
*)
	makedepends="$makedepends lld"
	export LDFLAGS="$LDFLAGS -fuse-ld=lld"
	;;
esac

build() {
	CC=clang CXX=clang++ \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON \
		-DMOLD_LTO=ON \
		-DMOLD_USE_SYSTEM_MIMALLOC=ON \
		-DMOLD_USE_SYSTEM_TBB=ON \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)"

	cmake --build build
}

check() {
	ctest --output-on-failure --test-dir build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
e332d027f783dfb0a4f48b1fb7daf98e11e830f8de82b971b58ee8a7bae59eaa30b8155e7491b6057f0ce8e0b09ddd0ab1d364f01ea15517e1d089fdb292a4e5  mold-2.4.0.tar.gz
9a54c572df99c79e501806ad08cf5e0f5ef7a91f02c973c6e9a86980b1e1fadb0f028746f160bcf89933453a1854e481136ee2fbfb2dbde7f0f53b16e215bd71  xxhash.patch
"
